#region Microsoft Public License
/*
 * (c) Copyright Chenjun Wu. http://utablesdk.codeplex.com
 * 
 * This source is subject to the Microsoft Public License (Ms-PL).
 * Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
 * All other rights reserved.
 */
#endregion

﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Controls.Primitives;
using System.Globalization;
using System.IO;

namespace UTable.Objects.Controls
{
    /// <summary>
    /// Interaction logic for FileItemView.xaml
    /// </summary>
    public partial class FileItemView : FileItemViewBase
    {
        public FileItemView()
        {
            InitializeComponent();
        }
    }

    [ValueConversion(typeof(String), typeof(ImageSource))]
    public class FileIconSelector : IValueConverter
    {
        public object Convert(object value, Type typeTarget, object param, CultureInfo culture)
        {
            object result = value;
            if (value != null)
            {
                String folder = "..\\..\\Images\\FileIcons\\";
                String path = value as String;
                FilePathType type = FileItemViewBase.CheckPathType(path);
                switch (type)
                {
                    case FilePathType.Photo:
                        result = folder + "picFile.png";
                        break;
                    case FilePathType.Video:
						result = folder + "vidoFile.png";
                        break;
                    case FilePathType.Music:
                        result = folder + "musicFile.png";
                        break;
                    case FilePathType.Document:
                        result = folder + "docFile.png";
                        break;
                    case FilePathType.Other:
                        result = folder + "unkonwFile.png";
                        break;
                }
            }
            return result;
        }
        public object ConvertBack(object value, Type typeTarget, object param, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    public class FileNameSelector : IValueConverter
    {
        public object Convert(object value, Type typeTarget, object param, CultureInfo culture)
        {
            object result = value;
            if (value != null && typeTarget == typeof(String))
            {
                String path = value as String;
                if (IsDiskName(path))
                    return path;
                result = System.IO.Path.GetFileName(path);
            }
            return result;
        }
        public object ConvertBack(object value, Type typeTarget, object param, CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        public static bool IsDiskName(String path)
        {
            return path[1] == ':' && path.Length <= 3;
        }
    }
}
